﻿/**
 * Copyright 2009 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using mooseirc.utility;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace mooseirc.irc
{

    /// <summary>
    /// Represents an IRC Command
    /// </summary>
    [CLSCompliant(true)]
    public abstract class IrcCommand : object, IDisposable
    {

        #region [Construction]

        /// <summary>
        /// Initializes IrcCommand
        /// </summary>
        public IrcCommand()
            : base()
        {
            
            return;
        }

        #endregion

        #region [Validation]

        /// <summary>
        /// Commands must specify valid IrcStates
        /// </summary>
        /// <returns>Valid IRC States</returns>
        protected abstract IrcState validStates();

        #endregion

        #region [Operation]

        /// <summary>
        /// Execute the command
        /// </summary>
        /// <returns>Trigger</returns>
        internal virtual void execute(IrcConnection connection, IrcState state, string args, Stream outputStream)
        {
            if (validStates().validIrcState(state))
            {
                action(connection, state, args, outputStream);
            }
            return;
        }

        /// <summary>
        /// Action Command .. does
        /// </summary>
        protected abstract void action(IrcConnection connection, IrcState state, string args, Stream outputStream);

        #endregion

        #region IDisposable Members

        /// <summary>
        /// Dispose IrcCommand
        /// </summary>
        public void Dispose()
        {
            //_connection.Dispose();
            return;
        }

        #endregion
    }
}
